﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DiscreteEventModel {

    using Common;

    public abstract partial class DiscreteEvent<TContext> : ITokenizable<int> 
        where TContext : class {

        private DiscreteTime _time;
        int ITokenizable<int>.Token { get; set; }

        private DiscreteEvent() { }

        protected DiscreteEvent(IProcess process, double delay, IEnumerable<Agent> targets) {
            if(double.IsPositiveInfinity(delay) || delay <= 0) {
                throw new Exception();
            }
            this._time = (process as EngineProcess)._time + delay;
            Parallel.ForEach(targets, target => {
                target._eventQueue.Enqueue(this);
            });
        }
    }
}
